package com.qzone;
import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;


public class AsynHttp extends AsyncTask<Integer, Void, String> {
	Context context;
	ProgressDialog pDialog;
	
	int flag;
	String values,ip;
	public static final int STDADD=1;
	public static final int STDLOG=2;
	AsynHttp(Context c,String SIPNumber,String v){
		context=c;
		values=v;
		ip=CommonUtil.longToIp(Long.parseLong(SIPNumber));
	}

	@Override
	protected String doInBackground(Integer... arg0) {
		// TODO Auto-generated method stub
		flag=arg0[0];
		ServiceHandler sh = new ServiceHandler();
		String URL="http://"+ip+"/ww";
		String jsonStr = null;
		
		switch (flag) {
		case STDADD:
			URL+="/json_student_add.asp";
			break;
		case STDLOG:
			URL+="/json_student_log.asp";
			break;	
			

		default:
			break;
		}
			
		Log.d("API REQUEST",URL+"?"+values+"&regid="+CommonUtil.getPref(context, CommonUtil.GCMREGID));
		jsonStr = sh.makeServiceCall(URL+"?"+values+"&regid="+CommonUtil.getPref(context, CommonUtil.GCMREGID), ServiceHandler.GET);
		
		return jsonStr;
	}
	
	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		// Showing progress dialog
		pDialog = new ProgressDialog(context);
		pDialog.setMessage("Please wait...");
		pDialog.setCancelable(false);
		pDialog.show();

	}
	
	
	@Override
	protected void onPostExecute(String result) {
		Log.d("API RESPONSE",result);
		super.onPostExecute(result);
	
		if (pDialog.isShowing())
			pDialog.dismiss();
		
		switch (flag) {
		case STDADD:
			AddStudent.stdAddResponse(result);
			break;
		case STDLOG:
			LocationList.locationRes(result);
			break;
		default:
			break;
		}

		
		
		// Dismiss the progress dialog
	
	
	}
	
	
	
	
}
